package com.fjnldx.mes.mapper.common;

import com.fjnldx.mes.domain.domainReq.QueryParamReq;
import com.fjnldx.mes.domain.pojo.QueryParam;
import com.fjnldx.mes.domain.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface CommonMapper {
    /**
     * 测试
     */
    @Select("SELECT * FROM `fzy_dictionary_data`")
    List<Map<String,Object>> test();

    /**
     * 用户登录
     */
    @Select("select * from user where username=#{username} and password=#{password}")
    List<User> usersLogin(User user);

    /**
     * 是否已注册
     */
    @Select("select * from user where phone=#{phone}")
    User isRegister(User user);

    /**
     * 用户注册
     */
    @Insert("insert into user(username,password,phone,qq,wx) values(#{username},#{password},#{phone},#{qq},#{wx})")
    int userRegister(User user);

    /**
     * 更新用户信息
     *
     * @return int
     */
    @Update("<script> " +
            "update user " +
            "<trim prefix='set' suffixOverrides=','>" +
            "<if test='username!=null'> username=#{username}, </if> " +
            "<if test='password!=null'> password=#{password}, </if> " +
            "<if test='phone!=null'> phone=#{phone}, </if> " +
            "<if test='qq!=null'> qq=#{qq}, </if> " +
            "<if test='wx!=null'> wx=#{wx}, </if> " +
            "</trim>" +
            "where id=#{id}" +
            "</script>")
    int updateUserInfo(User user);

    /**
     * 注销用户
     *
     * @return int
     */
    @Delete("DELETE FROM user WHERE id=#{id}")
    int deleteUser(Integer id);

    /**
     * 插入数据字典设备
     */
    @Insert("insert into fzy_dictionary_data_list(key_name,key_value,dic_bh) values(#{key_name},#{key_value},#{dic_bh})")
    int insertEquipment(String key_name,String key_value,String dic_bh);


    /**
     * 获取查询使用的参数
     * @param queryParamReq
     * @return
     */
    @Select("select id, type, dict_code dictCode, dict_value dictValue from query_param where type = #{type}")
    List<QueryParam> queryParam(QueryParamReq queryParamReq);
}
